package cn.seecoder.ai.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author fanyanpeng
 * @date 2023/4/6 0:34
 * 配置Swagger
 */
@Slf4j
@EnableOpenApi
@EnableWebMvc
@Configuration
public class OpenApiConfig {

    @Bean
    public Docket createRestApi() {
        log.info("swagger url: http://localhost:8080/swagger-ui/index.html");
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.seecoder.ai.controller"))
                .paths(PathSelectors.any())
                .build()
                .enable(true);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("AI子系统")
                .description("这是一个毕业设计项目")
                .termsOfServiceUrl("...")
                .version("v0.1")
                .license("...")
                .licenseUrl("...")
                .build();
    }
}
